package cn.itcast.JONG;

import cn.itcast.domain.Student;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.ArrayList;

public class ObjectMapperTest {
    public static void main(String[] args) throws IOException {
        //新建
        ObjectMapper mapper = new ObjectMapper();
        //测试转换
        Student student = new Student(12, "张三", "123");
        String s = mapper.writeValueAsString(student);
        System.out.println(s);
        //测试集合转换
        ArrayList<Student> list = new ArrayList<>();
        list.add(new Student(1,"伊一","1"));
        list.add(new Student(2,"尔尔","2"));
        list.add(new Student(3,"伞伞","3"));
        String l = mapper.writeValueAsString(list);
        System.out.println(l);
        //测试反转
        Student readValue = mapper.readValue(s, Student.class);
        System.out.println(readValue);
    }
}
